import http from "@/http";

export type IndicatorSystemItem = {
  id: number;
  name: string;
  version: string;
};
/**
 * @description: 用于项目创建时选择指标体系
 */
export const getIndicatorSystemOptions = (): Promise<IndicatorSystemItem[]> => {
  return http
    .getReq({ url: "/api/indicator/system/display" })
    .then((res) => res.body);
};
export type IndicatorSystemDetailItem = {
  id: string; // 指标id
  name: string; // 指标名称
  nodeType: number;
  parentId?: number;
  systemId: number; // 指标体系id
  weights: string; // 分值， 对应权重
  score?: number;
  type: string; // 指标类型，对应assementLevel
  canApproval?: boolean; // 是否参与评分
  children: IndicatorSystemDetailItem[];
  status: number; // 指标状态
  approvalStatus: number; // 指标评审状态
  approvalResult: number; // 1 达标 -1 不达标 2 修订
};
/**
 * @description: 用于项目创建时指标筛选
 */
export const getIndicatorSystemDetailById = (
  indicatorSystemId: number
): Promise<{
  systemId: number;
  userId: number;
  indicators: IndicatorSystemDetailItem[];
}> => {
  return http
    .getReq({
      url: "/api/indicator/system/detail/" + indicatorSystemId,
      // params: { indicatorSystemId },
    })
    .then((res) => res.body);
};
/**
 * @description: 项目指标筛选完成后进行保存时调用
 */
export const saveProjectIndicatorSystem = (data: {
  projectId: number;
  systemId: number;
  indicators: IndicatorSystemDetailItem[];
}) => {
  return http
    .postReq({
      url: "/api/indicator/project/create",
      data,
    })
    .then((res) => res.body);
};
/**
 * @description: 用于项目资料填报时展示指标清单
 */
export const getProjectIndicatorsById = (
  projectId: string | number
): Promise<{
  indicators: IndicatorSystemDetailItem[];
  systemId: number;
  projectId: number;
  score?: number;
  actualScore?: number;
  namedScore?: number;
  status: number;
  projectName: string;
}> => {
  return http
    .getReq({
      url: "/api/indicator/project/" + projectId,
    })
    .then((res) => res.body);
};
/**
 * @description: 用于指标库显示我的指标体系列表
 */
export const getMyIndicatorSystem = (data: {
  current: number;
  pageSize: number;
  keyword: string;
}) => {
  const { current, pageSize, ...searchIndicatorDto } = data;
  return http
    .postReq({
      url: "/api/indicator/system/list/mine",
      params: { page: current, size: pageSize },
      data: searchIndicatorDto,
    })
    .then((res) => {
      const { body, total } = res;
      return {
        list: body,
        total,
      };
    });
};
/**
 * @description: 用于指标库显示所有启用的指标体系列表
 */
export const getAllIndicatorSystem = (data: {
  current: number;
  pageSize: number;
  keyword: string;
}) => {
  const { current, pageSize, ...searchIndicatorDto } = data;
  return http
    .postReq({
      url: "/api/indicator/system/publish/all",
      params: { page: current, size: pageSize },
      data: searchIndicatorDto,
    })
    .then((res) => {
      const { body, total } = res;
      return {
        list: body,
        total,
      };
    });
};
/**
 * @description: 所有指标体列表，后台管理用
 */
export const getAllIndicatorSystemForApproval = (data: {
  current: number;
  pageSize: number;
  keyword: string;
  tabStatus: string;
}) => {
  const { current, pageSize, tabStatus, ...searchIndicatorDto } = data;
  return http
    .postReq({
      url: `/api/indicator/system/list/${tabStatus}`,
      params: { page: current, size: pageSize },
      data: searchIndicatorDto,
    })
    .then((res) => {
      const { body, total } = res;
      return {
        list: body,
        total,
      };
    });
};
/**
 * @description: 创建项目指标
 */
export const createIndicatorSystem = (data: Record<string, any>) => {
  return http.postReq({
    url: "/api/indicator/system/create",
    data,
  });
};
// {
//   name: string;
//   version: string;
//   intro: string;
//   bias?: string;
//   scale?: string;
//   type?: string;
//   stage?: string;
//   capital?: string;
//   indicators: any[];
// }
/**
 * @description: 创建项目指标-智能推荐
 */
export const createIndicatorSystemByIntelligence = (
  data: Record<string, any>
) => {
  return http
    .postReq({
      url: "/api/indicator/system/create2",
      data,
    })
    .then((res) => res.body);
};
/**
 * @description: 获取指标体系基本信息
 */
export const getIndicatorSystemBasicInfo = (
  indicatorSystemId: number | string
) => {
  return http
    .getReq({
      url: `/api/indicator/system/info/${indicatorSystemId}`,
    })
    .then((res) => res.body);
};
/**
 * @description: 审核指标体系，后台审核用
 */
export const approveIndicatorSystem = (indicatorSystemId: number | string) => {
  return http.getReq({
    url: `/api/indicator/system/approve/${indicatorSystemId}`,
  });
};
/**
 * @description: 拒绝指标体系，后台审核用
 */
export const rejectIndicatorSystem = (indicatorSystemId: number | string) => {
  return http.getReq({
    url: `/api/indicator/system/reject/${indicatorSystemId}`,
  });
};
/**
 * @description: 发布指标体系，后台管理用
 */
export const publishIndicatorSystem = (indicatorSystemId: number | string) => {
  return http.getReq({
    url: `/api/indicator/system/publish/${indicatorSystemId}`,
  });
};
/**
 * @description: 取消发布指标体系，后台管理用
 */
export const disableIndicatorSystem = (indicatorSystemId: number | string) => {
  return http.getReq({
    url: `/api/indicator/system/disable/${indicatorSystemId}`,
  });
};
/**
 * @description: 用于项目创建时指标智能推荐
 */
export const getRecommendIndicatorSystem = (data: {
  indicatorSystemId: number;
  projectId: number;
}): Promise<
  {
    indicatorId: number;
    indicatorName: string;
  }[]
> => {
  return http
    .postReq({
      url: `/api/indicator/system/indicator/recommend`,
      data,
    })
    .then((res) => res.body);
};
/**
 * @description: 用于指标体系创建时搜索推荐指标
 */
export const getRecommendIndicators = (data: {
  bias?: string; // 偏重体系
  scale?: string; // 适用规模
  type?: string; // 适用类型
  stage?: string; // 适用阶段
  capital?: string; // 资产组合类型
  name?: string;
  intro?: string;
  version?: string;
}) => {
  return http
    .postReq({
      url: `/api/indicator/system/search`,
      data,
    })
    .then((res) => res.body);
};
/**
 * @description: 用于指标体系设置权重
 */
export const updateIndicatorWeights = (data: {
  indicators: Record<string, any>[];
  systemId: number;
}) => {
  return http
    .postReq({
      url: `/api/indicator/system/wights`,
      data,
    })
    .then((res) => res.body);
};
